package workexp.alg.sort;

import org.junit.Test;

public class FirstBadVersion {
    public int firstBadVersion(int n) {
        int left=1,right=n;
        int mid = (right-left)/2+left;
        while(left<right){
            if(isBadVersion(mid)){
                right=mid;
            }else{
                left=mid+1;
            }
            mid = (right-left)/2+left;
        }
        return mid;
    }

    private boolean isBadVersion(int n){
        //4是错的
        return n>1;
    }

    @Test
    public void test(){
        int target = firstBadVersion(2);
        System.out.println(target);
    }
}
